package PTA_JAVA.JavaB.Javademo17;

import java.time.LocalDate;
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] types = {"Student","Teacher"};
        //输入种子seed，并用其初始化Random对象
        int seed = Integer.parseInt(sc.next());
        Random random = new Random(seed);
        //输入对象生成数量n
        int n = Integer.parseInt(sc.next());
        Person[] p = new Person[n];
        //以下是生成n个对象的循环
        for (int i = 0; i < n; i++) {
            //使用random.nextInt(2)从types数组中随机选取元素x并输出
            String s=types[random.nextInt(2)];
            //根据x选择输入相应的参数
            if(s.equals("Student")){
                Student stu=new Student(i, sc.next(), Integer.parseInt(sc.next()), Integer.parseInt(sc.next()), Integer.parseInt(sc.next()), Integer.parseInt(sc.next()), sc.next());
                p[i] = stu;
                System.out.println("Student");
            }else if(s.equals("Teacher")){
                Teacher tea = new Teacher(i, sc.next(), Integer.parseInt(sc.next()), Integer.parseInt(sc.next()), Integer.parseInt(sc.next()), sc.next(), Double.parseDouble(sc.next()));
                p[i] = tea;
                System.out.println("Teacher");
            }
        }
        //输出n个对象getPersonNumber
        for(Person i:p){
            System.out.println(i.getPersonNumber());
        }
        //以下几行输出验证信息，请直接复制粘贴到你的代码中
        System.out.println(Student.class.getSuperclass());
        System.out.println(Teacher.class.getSuperclass());
        try {
            System.out.println(Person.class.getDeclaredMethod("getPersonNumber", null));
            System.out.println(Student.class.getDeclaredMethod("getPersonNumber", null));
            System.out.println(Teacher.class.getDeclaredMethod("getPersonNumber", null));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
abstract class Person{
    private int id;
    private String name;
    private LocalDate birthDate;

    public Person(int id, String name,int year,int month,int dayOfMonth) {
        this.id = id;
        this.name = name;
        //字符不足2位，用String.format补齐0
        this.birthDate = LocalDate.parse(year+"-"+String.format("%02d",month)+"-"+String.format("%02d",dayOfMonth));
    }

    public int getId() {
        return id;
    }

    public LocalDate getBirthDate() {
        return birthDate;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person [" +
                "id=" + id +
                ", name=" + name  +
                ", birthDate=" + birthDate +
                ']';
    }
    public abstract String getPersonNumber();
}
class Student extends Person{
    private int enrollmentYear;
    private String clazzName;
    private String name;

    public Student(int id, String name, int year, int month, int dayOfMonth,int enrollmentYear,String clazzName) {
        super(id, name, year, month, dayOfMonth);
        this.name=name;
        this.enrollmentYear = enrollmentYear;
        this.clazzName = clazzName;
    }
    @Override
    public String getPersonNumber(){
        return "Student-"+enrollmentYear+"-"+name;
    }
}
class Teacher extends Person{
    private String department;
    private double salary;
    private String name;

    public Teacher(int id, String name, int year, int month, int dayOfMonth,String department,double salary) {
        super(id, name, year, month, dayOfMonth);
        this.department = department;
        this.salary = salary;
        this.name=name;
    }

    @Override
    public String getPersonNumber() {
        return "Teacher-"+department+"-"+name;
    }
}
